package distributedbank.requests;
import java.io.IOException;
import java.io.Serializable;

import distributedbank.responses.BalanceResponse;
import distributedbank.server.BankBranch;
import distributedbank.Wrapper;

/**
 * A request to display the amount of cash in an account.
 */
public class QueryRequest extends GUIRequest {
	private static final long serialVersionUID = -1179213294970307900L;
	public QueryRequest(int branchId, int accountId, int transactionId,
                        int originatingClientId) {
        super(branchId, accountId, transactionId, originatingClientId);
    }
    public void runRequest(BankBranch bankBranch, Wrapper wrapper) 
                throws IOException {
        System.out.println("Querying account " + this.accountId +
                           " at branch " + this.branchId);
        int balance = bankBranch.getAccount(this.accountId).query(this.transactionId);
        Serializable message = new BalanceResponse(balance);
        wrapper.sendMessage(message, this.branchId, this.originatingClientId);
    }
}
